var Debug = {
	startTime: (new Date()).getTime(),
	isDebug: true,

	infoElement: null,
	onInfo: Prototype.emptyFunction,
	info: function(v){
		if(!this.isDebug)
			return;
		this.onInfo(v);
		v = Object.inspect(v);
		if(this.infoElement)
			$(this.infoElement).innerHTML = v.escapeHTML();
		else
			alert(v);
	},

	logElement: null,
	onLog: Prototype.emptyFunction,
	logs: [],
	log: function(msg, lv){
		if(!this.isDebug)
			return;
		this.onLog(msg, lv);
		lv = lv || 0;
		if(msg == null)
			msg = 'null';
		else if(typeof(msg) != 'string')
			msg = Object.toJSON(msg);
		var a = {
			index:this.logs.length,
			message:msg, 
			level:lv, 
			time:  (new Date()).getTime()-this.startTime,
			toString: function(){
				return '['+this.index+']('+this.level+'){'+this.time+'ms}: '+this.message;
				}
		};
		this.logs.push(a);
		if(this.logElement)
			$(this.logElement).innerHTML += a.toString().escapeHTML()+'<br>';
	},
	clearLogs: function(){
		this.logs = [];
		if(this.logElement)
			$(this.logElement).innerHTML = '';
	}
};

var info = function(v){Debug.info(v);};
var log = function(msg, lv){Debug.log(msg, lv)};